package com.zhaojindong.ioc.component.autowiring;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
@ComponentScan
public class MainConfig {


    private Car car;

    @Bean
    @Primary
    @Qualifier("car")
    public Car customCar() {
        Car car = new Car(2);
        return car;
    }

    // @Bean 声明的方法，不写@Autowired，car组件也可以注入
    @Bean
    public Boss customBoss(Car car) {
        Boss boss = new Boss();
        boss.setCustomCar(car);
        return boss;
    }
}
